using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;

namespace lang_benchmarks
{
    public class klasa
    {
        public int n=1;
        public int getn()
        {
            return n;
        }

        public int propn
        {
            get{return n;}
        }
    }


    public interface IFace
    {
        int getn();
    }
    public class KlasaI : IFace
    {
        int n = 1;
        #region IFace Members

        public int getn()
        {
            return n;
        }

        #endregion
    }

    abstract class baza
    {
        public abstract int getn();
    }
    class AKlasa : baza
    {
        int n = 1;
        public override int getn()
        {
            return n;
        }
    }

    [TestFixture]
    public class Virtualization
    {
        [Test]
        public void functionVirtTest()
        {
            Timer T = new Timer();
            int tmp = 0;
            int n = 100000000;

            klasa K = new klasa();
            T.Start();
            for (int i = 0; i < n; i++) tmp += K.n;
            T.Stop();
            Console.WriteLine("n :" + T.Duration);
            T.Start();
            for (int i = 0; i < n; i++) tmp += K.getn();
            T.Stop();
            Console.WriteLine("getn() :" + T.Duration);
            T.Start();
            for (int i = 0; i < n; i++) tmp += K.propn;
            T.Stop();
            Console.WriteLine("propn :" + T.Duration);

            IFace I = new KlasaI();
            T.Start();
            for (int i = 0; i < n; i++) tmp += I.getn();
            T.Stop();
            Console.WriteLine("Igetn() :" + T.Duration);

            KlasaI KI = new KlasaI();
            T.Start();
            for (int i = 0; i < n; i++) tmp += KI.getn();
            T.Stop();
            Console.WriteLine("KIgetn() :" + T.Duration);

            baza A = new AKlasa();
            T.Start();
            for (int i = 0; i < n; i++) tmp += A.getn();
            T.Stop();
            Console.WriteLine("Agetn() :" + T.Duration);

            AKlasa AK = new AKlasa();
            T.Start();
            for (int i = 0; i < n; i++) tmp += AK.getn();
            T.Stop();
            Console.WriteLine("AKgetn() :" + T.Duration);

        }

    }
}
